﻿//=========================================
// Copyright©,1995-2007,厦门三五互联科技有限公司
// Create Date: 2007-04-??
// Author: xumq
// Modify Date: 2007-9-5
// Author: liaotl
// Modification: 增加Type和string的构造函数，
//	修改GetKey方法，并使用ExceptionThrowHelper
//=========================================

using System;
using System.Collections.Generic;
using System.Text;

namespace Framework.Caching
{
	/// <summary>
	/// 用于Cache保存时的键
	/// </summary>
    public class CacheKey
    {
        private string key;

        /// <summary>
        /// 初始化CacheKey的实例
        /// </summary>
        /// <param name="keys">用来组成键的多个字符串</param>
        public CacheKey(params string[] keys)
        {
            this.key = this.GetKey(keys);
        }

		/// <summary>
		/// 初始化CacheKey的实例
		/// </summary>
		/// <param name="type">类型</param>
		/// <param name="key">键</param>
		public CacheKey(Type type, string key)
		{
			this.key = this.GetKey(type.AssemblyQualifiedName, key);
		}

        /// <summary>
        /// 获取缓存关键字
        /// </summary>
        public string Key
        {
            get 
            {
                return this.key; 
            }       
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        private string GetKey(params string[] keys)
        {
			string k = "";
			for (int i = 0; i < keys.Length - 1; i++)
				k += keys[i] + ",";
			k += keys[keys.Length - 1];

			return k;
        }
    }
}
